﻿<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Cwjk_SelectFeeItem.aspx.vb" Inherits="PubProject.Cwjk_SelectFeeItem" %>
<%@ Register TagPrefix="mnu" Namespace="Mysoft.Map.Application.Menus" Assembly="Mysoft.Map.Application.Components" %>
<%@ Register TagPrefix="cnt" Namespace="Mysoft.Map.Application.Controls" Assembly="Mysoft.Map.Application.Components" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<head runat="server">
    <title>选择适用范围</title>
    <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
	<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
	<meta content="JavaScript" name="vs_defaultClientScript">
	<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
	<script language="javascript" src="/_controls/settings.aspx"></script>
	<LINK href="/_forms/styles/Form.css" type="text/css" rel="stylesheet">
	<LINK href="/_common/styles/dialogs.css" type="text/css" rel="stylesheet">
	<LINK href="/_common/styles/global.css" type="text/css" rel="stylesheet">
	<script language="javascript" src="/_controls/util/util.js"></script>
	<link rel="stylesheet" type="text/css" href="/_controls/tree/tree.css">
	<LINK href="/_grid/map_grid.css" type="text/css" rel="stylesheet">
	<LINK href="/_nav/menu.css" type="text/css" rel="stylesheet">
	<script language="javascript" src="/_common/scripts/global.js"></script>
	<script language="javascript" src="/_forms/FormBase.js"></script>
	<!-- GridTree -->
	<link rel="stylesheet" type="text/css" href="/_controls/tree/gridtree.css">
	<script language="javascript">
	    function window.onload()
	    {
	        //
	        if(document.all["txtSelectUsedScope"])
	        {
	            var sUsedScope = document.all["txtSelectUsedScope"].value;
	            if(sUsedScope != "")
	            {
	                sUsedScope = sUsedScope + "，";
	                var objTable = Table1;	            
			        for (var i = 0 ; i <= objTable.rows.length-1 ; i++)
			        {
				        var objCheck = objTable.rows[i].cells[0].children[2];
				        if ( sUsedScope.indexOf(objTable.rows[i].text + "，") >= 0)
				        {
					        //objCheck.checked = true;
					        objCheck.click();
				        }
			        }
	            }
	            
	        }
	        document.all["spanLevel"].innerHTML = document.all["sHtml"].value;
	    }
	    function showLevel(iLevel)
		{
			var i, j;
			for(i=0; i<Table1.rows.length; i++)
			{
				j = Table1.rows[i].code.split(".").length;
				if(j<iLevel)
				{
					if(Table1.rows[i].cells[0].children[1].innerText != "   ") Table1.rows[i].cells[0].children[1].innerText = "[-]";
					Table1.rows[i].IsHide = false;
					Table1.rows[i].style.display = "";
				}
				else if(j==iLevel)
				{
					if(Table1.rows[i].cells[0].children[1].innerText != "   ") Table1.rows[i].cells[0].children[1].innerText = "[+]";
					Table1.rows[i].IsHide = true;
					Table1.rows[i].style.display = "";
				}
				else
				{
					Table1.rows[i].IsHide = true;
					Table1.rows[i].style.display = "none";
				}
			}
			
		}
	    function selectNode(o)
		{
			var irowCount, sCode;

			var sSelectCode = o.parentElement.parentElement.code + "."

			irowCount = Table1.rows.length;
			
			//选中
			if (o.checked) 
			{
				for( var i = 0; i < irowCount; i++)
				{
					sCode = Table1.rows[i].code+".";
					//选中所有下级
					if ( sCode.indexOf(sSelectCode)==0 )
					{
						Table1.rows[i].cells[0].children[2].checked = true;
					}
				}
			}
			//取消选中
			else
			{
				for( var i = 0; i < irowCount; i++)
				{
					sCode = Table1.rows[i].code+".";
					//取消选中所有下级
					if ( sCode.indexOf(sSelectCode)==0 )
					{
						Table1.rows[i].cells[0].children[2].checked = false;
					}
				}
			}
			
			var sTempCode = o.parentElement.parentElement.code;
			var iNeedForI = sTempCode.split('.').length;
			var iIndex = 0;
			var iNowParentIndex = -1;
			var bSelectAllSubNode = true;
			var bNotSelectAnySubNode = true;

			for( var i = 0; i < iNeedForI; i++ )
			{
			    iIndex = sTempCode.lastIndexOf(".");
			    
		        if ( iIndex > 0 )
		        {
		            sTempCode = sTempCode.substr(0, iIndex);
		        }

		        for ( var j = 0; j < irowCount; j++ )
		        {
		            sCode = Table1.rows[j].code;
		            //校验当前节点的同级节点是否全部选中（含当前节点）
				    if ( bSelectAllSubNode && sCode.indexOf(sTempCode + ".")==0 )
				    {
				        bSelectAllSubNode = Table1.rows[j].cells[0].children[2].checked;
				    }
				    //校验当前节点的同级节点是否全部未选中（含当前节点）
				    if ( bNotSelectAnySubNode && sCode.indexOf(sTempCode + ".")==0 )
				    {
				        bNotSelectAnySubNode = !Table1.rows[j].cells[0].children[2].checked;
				    }
				    //获取当前节点的父级节点的索引
				    if (iNowParentIndex==-1 && sTempCode == sCode )
				    {
				        iNowParentIndex = j;
				    }
		        }

		        if ( bSelectAllSubNode && iNowParentIndex!=-1 )
			    {
			        Table1.rows[iNowParentIndex].cells[0].children[2].checked = true;
			    }
			    //else if ( bNotSelectAnySubNode && iNowParentIndex!=-1 )
			    //{
			        //alert("父级需要虚勾！")
			        //Table1.rows[iNowParentIndex].cells[0].children[2].checked = true;
			    //}
			    else if (  iNowParentIndex!=-1 )
			    {
			        Table1.rows[iNowParentIndex].cells[0].children[2].checked = false;
			    }
			    
			    bSelectAllSubNode = true;
		        bNotSelectAnySubNode = true;
		        iNowParentIndex = -1;
			}
			
		}
		function Ok()
		{
		    var objTable = Table1;
			var sFeeItem = "";
			for (var i = 0 ; i <= objTable.rows.length-1 ; i++)
			{
				var objCheck = objTable.rows[i].cells[0].children[2];
				if (objCheck.checked && objTable.rows[i].ifend == "True")
				{
					sFeeItem += ((sFeeItem=='')?'':'，') + objTable.rows[i].text;
				}
			}
			if (sFeeItem == "")
			{
				alert("请选择款项名称！");
				return;
			}
			parent.window.returnValue = sFeeItem ;
			parent.window.close();
		}
		function Clear()
		{
		    parent.window.returnValue = "" ;
			parent.window.close();
		}
	</script>
</head>
<body MS_POSITIONING="GridLayout" style="MARGIN: 5px">
	<form id="form1" runat="server">
		<asp:textbox id="txtSelectUsedScope" style="DISPLAY: none" Runat="server"></asp:textbox>
		<!-- 生成级数过滤按钮  -->
	    <input id="sHtml" type="hidden" name="sHtml" runat="server">
		<table height="100%" cellSpacing="0" cellPadding="0" width="100%">
			<tr height="1">
                <td >
                    <mnu:AppGridMenu id="appGridMenu" runat="server" />
                </td>
            </tr>
			<tr>
				<td >
					<table width="100%" cellspacing="0" cellpadding="0" height="100%" style="table-layout:fixed">
						<colgroup>
							<col>
							<col width="45">
						</colgroup>
						<TBODY>
							<tr>
								<td colspan="2" class="wizBox1">
									<DIV style="OVERFLOW: auto; WIDTH: 100%; HEIGHT: 100%" cellSpacing="0" cellPadding="0">
										<cnt:repeater id="repItem" runat="server" SortSignDESC='<img src="/_imgs/ico_arrow_d.gif">' SortSignASC='<img src="/_imgs/ico_arrow_u.gif">'
											PKField="BldCode" LinkAlign="right" LinkCssClass="a1" FooterCssClass="footer" EnablePager="false">
											<HeaderTemplate>
												<TABLE id="Table1" cellspacing="0" cellpadding="0" width="100%" class="singleSelectTree">
											</HeaderTemplate>
											<ItemTemplate>
												<tr height='20' code='<%# DataBinder.Eval(Container, "DataItem.ParamCode") %>'
													value='<%# DataBinder.Eval(Container, "DataItem.ParamGUID") %>'
													text='<%# DataBinder.Eval(Container, "DataItem.ParamValue") %>'
													ifend='<%# DataBinder.Eval(Container, "DataItem.IfEnd") %>'
													is_hide="false" onclick="Table1.clickNode(this)" 
													onmouseover='this.bgColor="#E3E9F4"' onmouseout='this.bgColor="#ffffff"'>
													<td  nowrap="true">
														<span></span><label style="CURSOR: hand"></label>
														<asp:CheckBox ID="chk_Select" Runat="server"  onclick="selectNode(this)"></asp:CheckBox><%# DataBinder.Eval(Container, "DataItem.ParamValue") %>
													</td>
												</tr>
											</ItemTemplate>
											<FooterTemplate>
												</table>
											</FooterTemplate> 
										</cnt:repeater>
									</DIV>
								</td>
							</tr>
					</table>
				</td>
			</tr>
			<TR height="40">
				<TD class="buttons" colSpan="2">
					<TABLE style="TABLE-LAYOUT: fixed; WIDTH: 100%; HEIGHT: 100%" cellSpacing="0" cellPadding="0">
						<TR>
							<TD align="right"><BUTTON style="WIDTH: 70px" onclick="Clear();" name="btnClear" type="button">清 
									空</BUTTON>&nbsp;&nbsp;<BUTTON style="WIDTH: 70px" onclick="Ok();" name="btnOK" type="button">确 
									定</BUTTON>&nbsp;&nbsp;<BUTTON style="WIDTH: 70px" onclick="parent.window.close();" name="btnClose" type="button"
									value="取 消">取 消</BUTTON>
							</TD>
						</TR>
					</TABLE>
				</TD>
			</TR>
		</table>
	</form>
</body>
</html>
